const { logsModel } = require('./models/logsModel');

//获取日志数据
module.exports.getLogs = async (cha, currentPage, pageSize) => {
  // console.log('3',cha,currentPage, pageSize);
  let total = await logsModel.countDocuments();//获取数据总条数
  const chao = await logsModel.find({ state: 2 });//已删除数据
  total = total - chao.length
  const pages = Math.ceil(total / pageSize);//数据总页数
  const data = await logsModel.find(cha)
    .populate('adminsId')
    .limit(pageSize)//设置请求数据条数
    .skip((currentPage - 1) * pageSize)//设置跳过数据条数
  // console.log('3',data);
  return { data, total, pages }
}
//新增日志
module.exports.addLogs = async (msg) => {
  const state = 1
  const data = await logsModel.create({adminsId:msg._id,state:state})
  return data
}

//修改日志数据
module.exports.setLogs = async (msg) => {
  _id=msg._id
  const data = await logsModel.updateOne({_id},msg)
  return data
}